<?php

class Dashboard_model extends CI_Model {

    function __construct() {
        parent::__construct();
        // $this->load->helper('url');    
        //parent::Model(); 
    }

    

    function getchart() {
        $s = $this->session->all_userdata();
        $tmp = $s['0'];
        $id = $tmp->id;

        $this->db->select('short_url,long_url,count(short_url)as hits');
        $this->db->from('track_url');
        $this->db->group_by('short_url');
        $this->db->order_by('hits', 'DESC');
        $this->db->where('url_owner', $id);
        $this->db->limit('10');        
        $query = $this->db->get();
     //   echo $this->db->last_query();
        return $query->result();
    }
    function totalurl(){
        return $this->db-> count_all_results('short_url');
        
    }
 public function yoururl() {
        $s = $this->session->all_userdata();
        $tmp = $s['0'];
        $id = $tmp->id;
        $this->db->where('user_id', $id);
        $this->db->from('short_url');
        return $this->db->count_all_results();
    }
     function totalhits(){
        return $this->db-> count_all_results('track_url');
        
    }
    function totaluser(){
        return $this->db-> count_all_results('url_users');
        
    }
    function browserHits(){
        $s = $this->session->all_userdata();
        $tmp = $s['0'];
        $id = $tmp->id;
        $this->db->select('browser, count(*) as hits ');
        $this->db->from('track_url');
        $this->db->group_by('browser');
        $this->db->where('url_owner', $id);
        $this->db->order_by('hits', 'ASC');
        $this->db->limit('10');
         $query = $this->db->get();
      //   echo $this->db->last_query();
        return $query->result();
        
    }
    function osHits(){
        $s = $this->session->all_userdata();
        $tmp = $s['0'];
        $id = $tmp->id;
        $this->db->select('os, count(*) as hits ');
        $this->db->from('track_url');
        $this->db->group_by('os');
        $this->db->where('url_owner', $id);
        $this->db->order_by('hits', 'ASC');
        $this->db->limit('10');
         $query = $this->db->get();
      //   echo $this->db->last_query();
        return $query->result();
        
    }
    function countryHits(){
        $s = $this->session->all_userdata();
        $tmp = $s['0'];
        $id = $tmp->id;
        $this->db->select('ip_detail.country_code, ip_detail.country_name, COUNT(track_url.ip) AS hits');
        $this->db->from('ip_detail');
        $this->db->join('track_url', 'ip_detail.ip=.track_url.ip', 'right');
        $this->db->where('track_url.url_owner', $id);
        $this->db->group_by('track_url.ip');
        $this->db->order_by('hits', 'DESC');
        $this->db->limit('10');
        $query = $this->db->get();
       // echo $this->db->last_query();

       return  $query->result();
    }
}

?>